class CellsController < ApplicationController
  
  def index
    @cell_pages, @cells = paginate :cells, :per_page => 10
  end
  
  def new
    @cell = Cell.new(:name => 'Enter name here...')
  end
  
  def create
    raise "not a post" unless request.post?
    
    @cell = Cell.new(params[:cell]) 
    
    if @cell.valid?
      @cell.save
      flash[:info] = 'Your cell has been saved!!'
      redirect_to :action => 'index'
    else   
      flash[:error] = cell.errors.full_messsages.join('<br/>')
      render :template => 'index'
    end
  end
  
  def download
    @cell = Cell.find(params[:id])
    send_file(@cell.path,
      :filename     => @cell.filename,
      :type         => @cell.mime,
      :disposition  => 'attachment',
      :streaming    => 'true',
      :buffer_size  => '4096')
  end
  
  def destroy
    Cell.find(params[:id]).destroy
    redirect_to :action => 'index'
  end

  # GET /cells/1
  # GET /cells/1.xml
  def show
    @cell = Cell.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @cell.to_xml }
    end
  end
  
  # GET /cells/contents/1
  def contents
    @cell = Cell.find(params[:id])
    @response.headers["Content-type"]=@cell.mime
    render_text @cell.contents
  end
end